#ifndef _BSP_W25Q64_H__
#define _BSP_W25Q64_H__

#include "gd32f4xx.h"
#include "spi4.h"

// CS 片选
#define W25Q_CS_PORT_RCU	        RCU_GPIOF
#define W25Q_CS_PORT			        GPIOF
#define W25Q_CS_PIN				        GPIO_PIN_6

#define W25Q_CS_SELECT()		    	gpio_bit_write(W25Q_CS_PORT, W25Q_CS_PIN, RESET)
#define W25Q_CS_UNSELECT()		    gpio_bit_write(W25Q_CS_PORT, W25Q_CS_PIN, SET)
// 引入spi函数
#define W25Q_SPI_RD_WR(data)	    SPI4_read_write_byte(data)
#define SPI_INIT()	              SPI4_init()




void W25Q64_init(void);
uint16_t W25Q64_readID(void);
void W25Q64_write(uint8_t* buffer, uint32_t addr, uint16_t numbyte);
void W25Q64_read(uint8_t* buffer, uint32_t read_addr, uint16_t read_length);
#endif


//测试代码
// #include "bsp_w25q64.h"
// #include "string.h"

// uint8_t cnt = 0;

// void Usart0_on_recv(uint8_t* data, uint32_t len) {

//     printf("recv: %X\r\n", data [0]);

//     if (data [0] == 0x00) {
//         printf("ID = %X\r\n", W25Q64_readID());
//     } else if (data [0] == 0x01) {
//         char buff [128];
//         sprintf(buff, "hello: %d", cnt++);
//         printf("write: %s (%d)\r\n", buff, strlen(buff));

//         W25Q64_write((uint8_t*)buff, 0, strlen(buff));
//     } else if (data [0] == 0x02) {
//         uint8_t buff [128];
//         W25Q64_read(buff, 0, 16);

//         printf("read: %s (%d)\r\n", (char*)buff, strlen((char*)buff));
//     }

// }


// int main(void) {
//     systick_config();
//     Usart0_init();
//     SPI_init();

//     W25Q64_init();

//     while (1) {

//     }
// }